package com.ylx.web.y;

import com.ylx.pojo.Order;
import com.ylx.pojo.Time;
import com.ylx.pojo.User;
import com.ylx.service.OrderService;
import com.ylx.service.OrderServiceImpl;
import com.ylx.service.UserService;
import com.ylx.service.UserServiceIpml;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;

@WebServlet("/selectsServlet")
public class Select2Servlet extends HttpServlet {
    private OrderService orderService=new OrderServiceImpl();
    private UserService userService=new UserServiceIpml();
    protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String year = request.getParameter("birthYear");

        String birthMonth = request.getParameter("birthMonth");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        User us = (User) session.getAttribute("us");
        String uid = user.getUid();


        List<Order> orderList = orderService.getOrderByUid(uid,year,birthMonth);

        request.setAttribute("orderList", orderList);
        Calendar calendar = Calendar.getInstance();
        String t = Time.getDateFormat(calendar.getTime(),"yyyy-MM-dd HH:mm:ss");
        request.setAttribute("t",t);
        request.setAttribute("user1",us);
        request.setAttribute("year",year);
        request.setAttribute("month",birthMonth);

        request.getRequestDispatcher("/yuedu.jsp").forward(request,response);
    }

    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);

    }
}

